package com.unsiv.torch;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.google.ads.AdRequest;
import com.google.ads.AdView;
/**
 * <p>Information</p>
 * @author fanzhen
 * @time   8:29:42 PM Aug 26, 2011
 * @email  fanzhen.meng@gmail.com
 */
public class Information extends Activity {
	private AdView adView;
	private WebView webView;
	private ImageView ibutton_information;
	private ImageView ibutton_help;
	private LinearLayout layout;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(new LinearLayout(this));
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
		ImageView window_title = (ImageView)findViewById(R.id.window_title_name);
		window_title.setBackgroundResource(R.drawable.title_information);
		setContentView(R.layout.information);
		// // Create the adView
		adView = (AdView) findViewById(R.id.adView);
		// // Initiate a generic request to load it with an ad
		adView.loadAd(new AdRequest());
		layout = (LinearLayout)findViewById(R.id.layout);
		layout.setBackgroundResource(R.drawable.bg_white);
		webView = (WebView) findViewById(R.id.webview_compontent);
		ibutton_information = (ImageView) findViewById(R.id.program_information);
		ibutton_help = (ImageView) findViewById(R.id.program_help);
		ibutton_information.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				if(webView.canGoBack()){
					webView.goBack();
				}else{
					onBackPressed();
				}
			}
		});
		ibutton_help.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				onBackPressed();
			}
		});
		webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
		WebSettings settings = webView.getSettings();
		settings.setJavaScriptEnabled(true);
		settings.setBuiltInZoomControls(true);
		webView.loadUrl("file:///android_asset/information/index.html");
	}
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(0, 0, 0, "Exit");
		return true;
	}
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case 0:
			MyCamaraHelper.turnOff();
			new ActivityUtil(this).exit();
			return true;
		}
		return false;
	}
}
